TAG_YINDAO = 1001;
TAG_SHIZHAN = 1002;
TAG_QUWEI = 1003;
TAG_ABOUT = 1004;
TAG_BACK = 1005;

TAG_ABOUT_CLICK=1401;
TAG_KEHOU=1402;
TAG_GUANYU=1403;
//TAG_TEST = 1402;



var StartMainLayer = cc.Layer.extend({
	lead:null,
	real:null,
	isOpen:false,
    ctor:function () {
        this._super();
        // 加载菜单栏按钮
        this.loadButton();
        this.loadVersion();
        this.loadTitle();
        this.loadInstruction();
        this.loadAbout();
        this.loadBack();
        return true;
    },
    loadButton:function(){
    	this.menu = new cc.Menu();
    	
    	this.show1 = new cc.LayerColor(cc.color(46,45,60),118,186);
    	this.addChild(this.show1, 8);
    	this.show1.setPosition(cc.p(58,356));
    	
    	this.lead = new cc.MenuItemImage("#leadButton1.png","#leadButton2.png",this.callback,this);
    	this.lead.setPosition(56+this.lead.width*0.5,gg.height-226-this.lead.height*0.5);
    	
    	this.real = new cc.MenuItemImage("#realButton1.png","#realButton2.png",this.callback,this);
    	this.real.setPosition(this.lead.x,this.lead.y-this.lead.height-10);
    	
    	this.game = new cc.MenuItemImage("#gameButton1.png","#gameButton2.png",this.callback,this);
    	this.game.setPosition(this.lead.x,this.real.y-this.real.height-10);
    	   	 	
    	this.about = new cc.MenuItemImage("#aboutButton1.png","#aboutButton2.png",this.callback,this);
    	this.about.setPosition(this.lead.x,this.game.y-this.game.height-10);

    	this.addChild(this.menu, 11);
    	this.menu.setPosition(cc.p(0,0));
    	this.menu.addChild(this.game, 1, TAG_QUWEI);
    	this.menu.addChild(this.lead, 1, TAG_YINDAO);
    	this.menu.addChild(this.about, 1, TAG_ABOUT);
    	this.menu.addChild(this.real, 1, TAG_SHIZHAN);

    },
    loadAbout:function(){
    	this.show2 = new cc.LayerColor(cc.color(46,45,60),58,78);
    	this.addChild(this.show2, 7,TAG_ABOUT_CLICK);
    	this.show2.setPosition(cc.p(59,356));   	
    	
    	this.kehou = new Button(this.show2,2,TAG_KEHOU,"#testButton1.png","#testButton2.png",this.callback);
    	this.kehou.setPosition(cc.p(this.show2.width,this.kehou.height*1.5));

    	this.guanyu = new Button(this.show2,2,TAG_GUANYU,"#aboutButton1.png","#aboutButton2.png",this.callback);
    	this.guanyu.setPosition(cc.p(this.show2.width,this.guanyu.height*0.5));

    	this.kehou.setScale(0.9);
    	this.guanyu.setScale(0.9);
    	this.kehou.setEnable(true);
    	this.guanyu.setEnable(true);

    },
    loadTitle : function(){
    	var title = new cc.LabelTTF("物质的构成",gg.fontName,30);
    	this.addChild(title, 5);
    	title.setColor(cc.color(152,10,5));
    	title.setPosition(cc.p(476+title.width*0.5,gg.height-126+title.height*0.5+20));
    },
    loadInstruction : function(){
    	var purpose = new cc.LabelTTF("实验目的：气体扩散",gg.fontName,30);
    	purpose.setColor(cc.color(97,98,95));
    	purpose.setAnchorPoint(0, 1);
    	purpose.setPosition(cc.p(417,gg.height-250));
    	this.addChild(purpose,6);
    	
    	var axiom = new cc.LabelTTF("实验原理：分子处于不停的运动之中",gg.fontName,30);
    	axiom.setColor(cc.color(97,98,95));
    	axiom.setAnchorPoint(0, 1);
    	axiom.setPosition(cc.p(417,purpose.y-58-axiom.height));
    	this.addChild(axiom,6);
    	
    	var instrument = new cc.LabelTTF("实验器材：玻璃瓶、玻璃板",gg.fontName,30);
    	instrument.setColor(cc.color(97,98,95));
    	instrument.setAnchorPoint(0, 1);
    	instrument.setPosition(cc.p(417,axiom.y-58-instrument.height));
    	this.addChild(instrument,6);
    },
    loadVersion : function(){
    	var version = new cc.LabelTTF(gg.version, gg.fontName, gg.fontSize);
    	version.setColor(cc.color(0,0,0,0));
    	version.setPosition(gg.width - version.width - 10, gg.height - version.height * 0.5 -10);
    	this.addChild(version);
    },
    loadBack:function(){
    	var back = new Button(this,2,TAG_BACK,"#back.png","#back.png",this.callback);
    	back.setPosition(cc.p(12+back.width*0.5,12+back.height*0.5));
    	back.setEnable(true);
    },
    callback:function(pSend){
    	switch(pSend.getTag()){
	    	case TAG_YINDAO:
	    		cc.log("进入引导模式");
	    		gg.teach_type = TAG_LEAD;
	    		this.runNext(pSend.getTag());
	    		break;
	    	case TAG_SHIZHAN:
	    		cc.log("进入实战模式");
	    		gg.teach_type = TAG_REAL;
	    		this.runNext(pSend.getTag());
	    		break;
	    	case TAG_QUWEI:
	    		cc.log("进入游戏模式");
	    		this.runNext(pSend.getTag());
	    		break;
	    	case TAG_ABOUT:
//	    		cc.log("关于我们");
//	    		this.runNext(pSend.getTag());
	    		if(this.isOpen){
	    			this.show2.runAction(cc.moveBy(0.6, 0,this.show2.height));
	    			this.isOpen = false;
	    		}else{
	    			this.show2.runAction(cc.moveBy(0.6, 0,-this.show2.height));
	    			this.isOpen = true;
	    		}
	    		break;
	    	case TAG_KEHOU:
	    		cc.log("课后练习");
	    		if(gg.game_load && gg.test_load){
	    			$.runScene(new TestScene());
	    			return;
	    		}
	    		break;
	    		break;
	    	case TAG_GUANYU:
	    		cc.log("关于我们");
	    		if(gg.about_load){
	    			$.runScene(new AboutScene());
	    			return;
	    		}
	    		break;
	    	case TAG_BACK:
	    		cc.log("能退到哪里去！");
	    		
	    		break;
//	    	case 9999:
//	    		if (cc.sys.platform == cc.sys.DESKTOP_BROWSER) {
//	    		} else if(cc.sys.os == "IOS"){
//	    			
//	    		} else if(cc.sys.os == "Android"){
//	    			cc.director.end();	
//	    		}
//	    	break;
    	}
    },
    runNext:function(tag){
    	switch(tag){
	    	case TAG_YINDAO:
	    	case TAG_SHIZHAN:
	    		if(gg.run_load){
	    			$.runScene(new RunScene());
	    			return;
	    		}
	    		break;
	    	case TAG_QUWEI:
	    		if(gg.game_load){
	    			 $.runScene(new GameScene());
	    			return;
	    		}
	    		break;
    	}
    	if(this.tip == null){
    		this.tip = new cc.LabelTTF("加载中，请稍候再试",gg.fontName,gg.fontSize);
    		this.tip.setColor(cc.color(0,0,0,0));
    		this.tip.setPosition(gg.width * 0.5, gg.height * 0.5)
    		this.addChild(this.tip);
    	} else {
    		this.tip.setVisible(true);
    	}
    	this.scheduleOnce(function(){
    		this.tip.setVisible(false);	
    	}.bind(this), 1.5);
    }
});
